package groep3.ssc.skaterViews;

import groep3.ssc.helpers.DataFunctions;
import groep3.ssc.main.R;
import groep3.ssc.model.Race;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Color;
import android.view.Gravity;
import android.widget.LinearLayout;
import android.widget.TextView;

public class OverView extends SkaterViewTemplate
{
    public TextView lastTime;
    public TextView distance;
    public TextView round;
    public TextView targetScheme;

    public OverView(Context context)
    {
        super(context);
        this.setGravity(Gravity.RIGHT | Gravity.TOP);

        setOrientation(LinearLayout.VERTICAL);

        lastTime = new TextView(getContext());
        lastTime.setTextSize(30);
        lastTime.setTextColor(Color.GRAY);
        addView(lastTime);
        distance = new TextView(getContext());
        distance.setTextSize(30);
        distance.setTextColor(Color.GRAY);
        addView(distance);
        round = new TextView(getContext());
        round.setTextSize(30);
        round.setTextColor(Color.GRAY);
        addView(round);
        targetScheme = new TextView(getContext());
        targetScheme.setTextSize(30);
        targetScheme.setTextColor(Color.GRAY);
        addView(targetScheme);

        subscribeToController();
    }

    @Override
    public void update(Race model)
    {
        Resources res = getResources();
        String lastLapString = res.getString(R.string.txtLastLapString);
        String targetSchemeString = res.getString(R.string.txtTargetSchemeString);
        String distanceString = res.getString(R.string.txtDistanceString);
        String roundString = res.getString(R.string.txtRoundString);
        this.lastTime.setText(lastLapString + ": "
                + DataFunctions.longToFormattedTime(model.getSkater(model.getOurSkater()).getLastLapTime()));
        if (model.getTargetScheme() != null)
        {
            this.targetScheme.setText(targetSchemeString + ": " + model.getTargetScheme().getTitle());
        }
        this.distance.setText(distanceString + ": " + model.getSkater(model.getOurSkater()).getTotalDistance() + " / "
                + model.getDistanceToSkate());
        this.round.setText(roundString + ": " + model.getSkater(model.getOurSkater()).getRoundNumber());
    }

    @Override
    public String toString()
    {
        Resources res = getResources();
        String overviewString = res.getString(R.string.txtOverviewString);
        return overviewString;
    }
}